<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>班级设置</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css">
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <style type="text/css">
        body {
            background: rgba(245, 245, 245, 1);
        }

        .box {
            background: rgba(255, 255, 255, 1);
            overflow: hidden;
        }

        .row {
            margin: 15px;
        }

        .title {
            font-size: 15px;
            font-weight: 400;
            color: rgba(25, 25, 25, 1);
        }

        .title-right {
            font-size: 13px;
            font-weight: 400;
            color: rgba(128, 128, 128, 1);
        }

        .arrow {
            width: 17px;
            height: 15px;
            margin-left: 6px;
        }

        .equal {
            width: 20%;
        }

        .image {
            width: 35px;
            height: 35px;
            border-radius: 50%;
            overflow: hidden;
            margin: 0 auto;
        }

        .name {
            font-size: 13px;
            font-weight: 400;
            color: rgba(25, 25, 25, 1);
            margin-top: 7px;
            text-align: center;
        }

        .space-block {
            height: 10px;
        }

        .content {
            font-size: 14px;
            font-weight: 400;
            color: rgba(128, 128, 128, 1);
            line-height: 20px;
        }

        .btn {
            width: 210px;
            height: 46px;
            margin: 22px auto;
            background: rgba(226, 83, 83, 1);
            box-shadow: 0px 4px 11px 0px rgba(0, 0, 0, 0.09);
            border-radius: 23px;
            font-size: 15px;
            font-weight: 400;
            color: rgba(255, 255, 255, 1);
            line-height: 21px;
        }
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>
        <div class="box">
            <div class="row" data-flex="main:justify cross:center" @click="memberFn()">
                <div class="title">
                    班级成员
                </div>
                <div data-flex="cross:center main:right">
                    <div class="title-right">
                        共{{ studentList.length + 1 }}人
                    </div>
                    <div class="arrow">
                        <img src="../../image/ui/arrow_right_2.png" alt="">
                    </div>
                </div>
            </div>
            <div class="row" style="margin: 15px 0;" data-flex>
                <div class="equal">
                    <div class="image">
                        <img :src="icon" alt="">
                    </div>
                    <div class="name">
                        {{ nickname }}
                    </div>
                </div>
                <div class="equal" v-for="item,index in studentList" v-if="index < 4" @click="handleStudentItem(item)">
                    <div class="image">
                        <img :src="item.icon" alt="">
                    </div>
                    <div class="name">
                        {{ item.name }}
                    </div>
                </div>
            </div>
        </div>
        <div class="space-block"></div>
        <div class="box">
            <div class="row" data-flex="main:justify cross:center">
                <div class="title">
                    班级资料
                </div>
            </div>
            <div class="row" style="margin: 15px 0;" data-flex>
                <div class="equal" @click="karaokeFn()">
                    <div class="image">
                        <img src="../../image/ui/data1.png" alt="">
                    </div>
                    <div class="name">
                        卡拉OK
                    </div>
                </div>
                <div class="equal" @click="classReportFn">
                    <div class="image">
                        <img src="../../image/ui/data2.png" alt="">
                    </div>
                    <div class="name">
                        班级报告
                    </div>
                </div>
                <div class="equal" @click="readReportFn">
                    <div class="image">
                        <img src="../../image/ui/data3.png" alt="">
                    </div>
                    <div class="name">
                        跟读报告
                    </div>
                </div>
                <div class="equal" v-if="userType == 2" @click="errorQuestionFn">
                    <div class="image">
                        <img src="../../image/ui/data4.png" alt="">
                    </div>
                    <div class="name">
                        错题集
                    </div>
                </div>
            </div>
        </div>
        <div class="space-block"></div>
        <div class="box">
            <div class="row" data-flex="main:justify cross:center"  @click="userType == 2 ? classNameFn() : ''">
                <div class="title">
                    班级名称
                </div>
                <div data-flex="cross:center main:right">
                    <div class="title-right">
                        {{ className }}
                    </div>
                    <div class="arrow" v-if="userType == 2">
                        <img src="../../image/ui/arrow_right_2.png" alt="">
                    </div>
                </div>
            </div>
        </div>
        <div class="space-block"></div>
        <div class="box">
            <div class="row" data-flex="main:justify cross:center" @click="classNoticesFn()">
                <div class="title">
                    班级公告
                </div>
                <div data-flex="cross:center main:right">
                    <div class="arrow">
                        <img src="../../image/ui/arrow_right_2.png" alt="">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="content" v-if="noticeList.length !== 0">
                    {{ noticeList[0].content }}
                </div>
                <div class="content" v-else>
                    当前班级没有公告
                </div>
            </div>
        </div>
        <div class="btn" v-if="userType == 1" data-flex="main:center cross:center" @click="fnOpenAlert({alertType:'6',alertConfirmFn: 'quitClassFn'})">
            退出班级
        </div>
        <div class="btn" v-else="userType == 2" data-flex="main:center cross:center" @click="fnOpenAlert({alertType:'7',alertConfirmFn: 'disbandClassFn'})">
            解散班级
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm, pageParam;
    apiready = function () {
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        // 如果班级公告发生变更
        api.addEventListener({
            name: 'classNoticeChange'
        }, function (ret, err) {
            getPageData();
        });
        api.addEventListener({
            name: 'deleteStudent'
        }, function() {
            findClassesStudentList();
            getPageData();
        });
        pageParam = api.pageParam;
        fnInit();
    };

    // 初始化
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                userType: getUserType(),
                className: '',
                studentCount: '',
                icon: '',
                nickname: '',
                noticeList: '',
                studentList: ''
            }
        });
        getPageData();
        findClassesStudentList();
    }

    // 获取页面数据
    function getPageData() {
        var url = 'clsClass/findClassesDetail';
        var params = {
            "id": pageParam.classesId
        };
        var callback = function (data) {
            vm.className = data.classesName;
            vm.studentCount = data.studentCount + 1;
            vm.icon = data.icon;
            vm.nickname = data.nickName;
            vm.noticeList = data.clsClassesNoticeList.filter(function(item) {
                return item.content !== '';
            });
            api.execScript({
                name: 'class/group_win',
                script: 'fnSetTitle("' + vm.className + "("+ vm.studentCount + "人)" + '");'
            });
            // status 为200时,只返回data
        };
        var error = function (res) {
            // status 不是200时,全部返回
            api.refreshHeaderLoadDone();
        };
        POST(url, params, callback, error);
    }

    // 班级人员接口
    function findClassesStudentList() {
        var url = 'clsClass/findClassesStudentList';
        var charset = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','未分组'];
        var params = {
            "id": pageParam.classesId
        };
        var callback = function (data) {
            var studentList = [];
            for(var i = 0; i < charset.length; i++) {
                studentList = studentList.concat(data[charset[i]]);
            }

            vm.studentList = studentList;
            // status 为200时,只返回data
        };
        var error = function (res) {
            // status 不是200时,全部返回
            api.refreshHeaderLoadDone();
        };
        POST(url, params, callback, error);
    }

    // 退出班级
    function quitClassFn() {
        var url = 'clsClass/quitClass';
        var params = {
            "classesId": pageParam.classesId
        };
        var callback = function (data) {
            fnToast('退出成功');
            api.execScript({
                name: 'main',
                frameName: 'tab_index_frm1',
                script: 'getPageData()'
            })
            api.closeToWin({
                name: 'main'
            })
            // status 为200时,只返回data
        };
        var error = function (res) {
            // status 不是200时,全部返回
            api.refreshHeaderLoadDone();
        };
        POST(url, params, callback, error);
    }

    // 解散班级
    function disbandClassFn() {
        var url = 'clsClass/dismissClass';
        var params = {
            "classesId": pageParam.classesId
        };
        var callback = function (data) {
            fnToast('解散成功');
            api.execScript({
                name: 'main',
                frameName: 'tab_index_frm1',
                script: 'getPageData()'
            })
            api.closeToWin({
                name: 'main'
            })
            // status 为200时,只返回data
        };
        var error = function (res) {
            // status 不是200时,全部返回
            api.refreshHeaderLoadDone();
        };
        POST(url, params, callback, error);
    }

    function memberFn() {
        fnOpenPublicWin(
            '班级成员',
            'class/class_member',
            {
                id: pageParam.classesId,
                teacherName: vm.nickname,
                teacherIcon: vm.icon
            }
        )
    }

    function karaokeFn() {
        fnOpenPublicWin(
            '来自班级的分享',
            'class/share',
            {
                clsClassesId: pageParam.classesId
            }
        );
    }

    // 班级报告
    function classReportFn() {
        // 班级，学期，单元->平均分，学生列表->详情
        // 右上无按钮
        fnOpenPublicWin('学习报告', 'class/select_model', {
            reportType: 1,
            from: 'class',
            classId: pageParam.classesId
        });
    }

    // 跟读报告
    function readReportFn() {
        // 班级，学期，单元->平均分，学生列表->详情
        // 右上无按钮
        fnOpenPublicWin('跟读报告', 'class/select_model', {
            reportType: 2,
            from: 'class',
            classId: pageParam.classesId
        });
    }

    // 错题集
    function errorQuestionFn() {
        // 错题率，学期->错题率，单元->错题率，学生->错题详情
        // 右上无按钮
        fnOpenPublicWin('错题集', 'class/review_data', {
            reportType: 11,
            from: 'class',
            classId: pageParam.classesId
        });
    }

    function classNameFn() {
        fnOpenPublicWin(
            '班级名称',
            'class/name',
            {
                classesId: pageParam.classesId,
                className: vm.className
            }
        )
    }

    function classNoticesFn() {
        var param = {
            classesId: pageParam.classesId,
        };
        if (USER.Get('memberType', true) == 2) {
            param = {
                classesId: pageParam.classesId,
                isBtn: true,
                btnName: '清空班级公告',
                headerFn: 'headerFn'
            }
        }
        fnOpenPublicWin(
            '班级公告',
            'class/notices',
            param
        )
    }

    // 点击学生
    function handleStudentItem(item) {
        if (USER.Get('memberType', true) == '2') {
            fnOpenPublicWin('学生资料', 'class/student_info', {
                item: item,
                classId: pageParam.classesId
            });
        }
    }
</script>

</html>